<meta >
<?php
/*
Lottery Intro
Alpha 1.00		Basic Name show
				link to history
Alpha 1.01	+	lottery Rule show 
				proability calculate
*/
?>
<?php
$aModList = xml2mod('lotteryMod/mod.xml');
foreach($aModList as $aMod)	{
	echo mod2html($aMod);
}
?>
<?php
function mod2html($aMod)	{
	$sHtml = "";
	//$sHtml.= $aMod["name"]."<br />";
	$sHtml.= mod2ahref($aMod,"history.php")."<br />";
	$aRule = showRule($aMod);
	if($aRule)	{
		$sHtml.=rule2Text($aRule,$aMod["file"]);
	}
	//$sHtml.= bingo2Text($aMod["name"]);
	$sHtml.="<hr />";
	return $sHtml;
}
?>
<?php
function rule2Text($aRule,$mod)	{
	//print_r($aRule);
	$sText = "";
	$sText.= "<b>玩法</b>"."<br />";
	$sText.= "分".$aRule["sector"]."区"."<br />";
	include_once("inc/factorialPC.php");
	foreach($aRule["amount"] as $key => $amount)	{
		$sText.="第".($key+1)."区有".$amount."个数范围系：".$aRule["range"][$key][0]."到".$aRule["range"][$key][1]."&nbsp;&nbsp;&nbsp;";
		$num_Range	= $aRule["range"][$key][1]-$aRule["range"][$key][0]+1;
		$num_Range	= (int)$num_Range;
		$amount		= (int)$amount;
		$proability[$key]	= C($num_Range,$amount);
		$sText.= "有".$proability[$key]."种可能"."<br />";
	}
	$proX	=	1;
	foreach($proability as $pro)	{
		$proX*=$pro;
	}
	$sText.="共有".$proX."种可能"."<br />";
	$sText.=bingo2Text($mod,$aRule,$proX);
	return $sText;
}
?>
<?php
function bingo2Text($mod,$aRule,$proX)	{
	$sText="";
	$sText.= "<b>奖率</b>"."<br />";
	include_once("inc/getBingoLvl.php");
	$aBingoLvl	=	getBingoLvl("bingo/".$mod.".csv");
	$iLost = $proX;
	foreach($aBingoLvl as $key => $bingoLvl)	{
		$sText.= $key.":<br />";
		$iZ=0;
		foreach($bingoLvl as $singleLvl)	{
			$iY=1;
			for($i=0;$i<$aRule["sector"];$i++)	{
				$bingo = (int)$singleLvl[$i];
				$select= (int)$aRule["amount"][$i];
				$range = (int)$aRule["range"][$i][1]-(int)$aRule["range"][$i][0]+1;
				$sText.= $bingo."/".$select."/".$range." ";
				$iX=C($range-$select,$select-$bingo);
				$iY*=$iX;
				$sText.= $iX." ";
			}
			$sText.= "=".$iY."<br />";
			$iZ+=$iY;
		}
		$sText.= $iZ."/".$proX."=".(float)($iZ/$proX*100)."%<hr />";
		$iLost -= $iZ;
	}
	$sText.= "Loser:".$iLost."/".$proX."=".(float)($iLost/$proX*100)."%<hr />";
	return $sText;
}
?>
<?php
function showRule($aMod)	{
	$file = 'lotteryMod/'.$aMod["file"].'.csv';
	if(file_exists($file))	{
		include_once("inc/lotteryMod.php");
		$aRule = lotteryMod($file);
		return $aRule;
	}
	else	{
		return False;
	}
}
?>
<?php
function mod2ahref($aMod,$file)	{
	$sHref = '<a href="'.$file.'?mod='.$aMod["file"].'">'.$aMod["name"].'</a>';
	return $sHref;
}
?>
<?php
function xml2mod($file)	{
	if (file_exists($file)) {
		$xml = simplexml_load_file($file);
	}
	else	{
		return False;
	}
	$aModList=array();
	foreach($xml as $xmlMod)	{
		$aModList[]=array("name"=>$xmlMod->name[0],"file"=>$xmlMod->file[0]);
	}
	return $aModList;
}
?>